package com.onpositive.funkytable.impl;

import com.onpositive.funkytable.IControlFactory;
import com.onpositive.funkytable.IFunkyComposite;
import com.onpositive.funkytable.Point;

public abstract class AbstractGroupLayout implements IGroupLayout{

	protected LabelAndValue[] members;
	protected Point deziredsize;


	public AbstractGroupLayout(LabelAndValue[] l, int from, int to) {
		LabelAndValue[] rs = new LabelAndValue[to - from+1];
		for (int a = from; a <= to; a++) {
			rs[a - from] = l[a];
		}
		this.members = rs;
		deziredsize=initLayout(members);
	}
	
	public final Point getDesiredSize(){
		return deziredsize;
	}
	
	public abstract IFunkyComposite create(int width,IControlFactory cf);

	protected abstract Point initLayout(LabelAndValue[] members2);
	
	public double usageRate(int width) {
		int x = getDesiredSize().x;
		if (x>width){
			return -1;
		}
		return ((double)x)/width;
	}

	
}
